package com.bird.设计模式.结构型.组合模式;

import java.util.ArrayList;
import java.util.List;

/**
 * @data 2022/3/15 17:37
 * @author: bird
 * @description: 课程目录类
 */
public class CourseCatalog extends CatalogComponent {
    // 目录节点
    private List<CatalogComponent> items = new ArrayList<>();

    //目录名称
    private String name;

    private Integer level; //课程目录等级

    public CourseCatalog(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public String getName(CatalogComponent catalogComponent) {
        return this.name;
    }

    @Override
    public void add(CatalogComponent catalogComponent) {
        items.add(catalogComponent);
    }

    @Override
    public void remove(CatalogComponent catalogComponent) {
        items.remove(catalogComponent);
    }


    @Override
    public void print() {
        System.out.println(this.name);
        for (CatalogComponent item : items) {
            if (level != null) {
                for (int i = 0; i < this.level; i++) {
                    System.out.print(" ");
                }
            }
            item.print();
        }
    }
}
